@extends('admin.layouts.head')
@section('content')
    <body>
    <div id="app">
        <div class="wrapper -header-fixed">

        @include('admin.layouts.navbar')
        @include('admin.layouts.sidebar')

        <!-- 内容页开始-->
            <div class="content-container">
                <div class="container-fluid">
                    <div class="page-content">

                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">仪表盘</a></li>
                                <li class="breadcrumb-item"><a href="{{ route('admin.payPlat.index') }}">平台列表</a></li>
                                <li class="breadcrumb-item active" aria-current="page">新增编辑</li>
                            </ol>
                        </nav>

                        <div class="card">
                            <div class="card-body">

                                <div class="row">
                                    <div class="col-lg-5">
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>平台名称：</label>
                                                <input type="text" class="form-control" id="plat_name" value="{{ $detail->plat_name ?? '' }}">
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>app_key：</label>
                                                <input type="text" class="form-control" id="app_key" value="{{ $detail->app_key ?? '' }}">
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>game_id：</label>
                                                <input type="text" class="form-control" id="game_id" value="{{ $detail->game_id ?? '' }}">
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>group_id：</label>
                                                <input type="text" class="form-control" id="group_id" value="{{ $detail->group_id ?? '' }}">
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>type_id：</label>
                                                <input type="text" class="form-control" id="type_id" value="{{ $detail->type_id ?? '' }}">
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>user_id：</label>
                                                <input type="text" class="form-control" id="user_id" value="{{ $detail->user_id ?? '' }}">
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>pay_version：</label>
                                                <input type="text" class="form-control" id="pay_version" value="{{ $detail->pay_version ?? '' }}">
                                            </div>
                                        </div>

                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>是否参与随机：</label>
                                                <select class="form-control" id="is_rand">
                                                    <option value="2" @if (!empty($detail->is_rand) && $detail->is_rand  == 2) selected @endif>不参与</option>
                                                    <option value="1" @if (!empty($detail->is_rand) && $detail->is_rand  == 1) selected @endif>参与</option>
                                                </select>
                                            </div>
                                        </div>

                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <button class="btn btn-primary" onclick="operation_tip2({{$detail->id ?? 0}})">提交</button>
                                            </div>
                                        </div>
                                    </div>

                                </div> <!-- .row -->
                            </div> <!-- .card-body -->
                        </div> <!-- .card -->

                    </div> <!-- .page-content -->
                </div> <!-- .container-fluid -->
            </div> <!-- .content-container -->
        </div> <!-- .wrapper -->
    </div> <!-- #app -->
    <script src="{{ mix('js/app.js') }}"></script>
    <script src="{{ asset('/js/main.js') }}"></script>
    <script>

        let isLoading = false;

        //提交
        function submit(id) {

            if (isLoading === false) {
                isLoading = true;

                axios.patch('{{ route('admin.payPlat.update','').'/' }}' + id + '', {
                    plat_name: $('#plat_name').val(),
                    app_key: $('#app_key').val(),
                    game_id: $('#game_id').val(),
                    group_id: $('#group_id').val(),
                    type_id: $('#type_id').val(),
                    user_id: $('#user_id').val(),
                    pay_version: $('#pay_version').val(),
                    is_rand: $('#is_rand option:selected').val(),
                })
                    .then(function (response) {
                        isLoading = false;
                        toast(response.data.message);
                        if (response.data.success === 'true') {
                            setTimeout(() => {
                                window.location.href='{{ route('admin.payPlat.index') }}';
                            }, 2000)
                        }
                    })
                    .catch(function (error) {
                        isLoading = false;
                        $.each(error.response.data.errors, function (index, object) {
                            toast(object[0]);
                            return false;
                        });
                    })
            }
        }

    </script>
    </body>

@endsection
